<template>
  <div class="inventory">
    <h2>背包</h2>
    <draggable v-model="items" @end="onEnd">
      <div v-for="(item, index) in items" :key="item.id" class="item">
        {{ item.name }}
      </div>
    </draggable>
  </div>
</template>

<script>
import draggable from 'vuedraggable';

export default {
  components: {
    draggable,
  },
  data() {
    return {
      items: [
        { id: 1, name: '剑' },
        { id: 2, name: '盾' },
        { id: 3, name: '头盔' },
      ],
    };
  },
  methods: {
    onEnd(event) {
      this.$emit('update-items', this.items);
    },
  },
};
</script>

<style scoped>
.inventory {
  width: 200px;
  border: 1px solid #ccc;
  padding: 10px;
  margin-right: 20px;
}
.item {
  padding: 5px;
  margin: 5px 0;
  background-color: #f0f0f0;
  cursor: grab;
}
</style>
